package freshmanspecial.mredrock.com.welcomefreshman.Adapter;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import freshmanspecial.mredrock.com.welcomefreshman.Bean.BeautyInCQUPTBean;
import freshmanspecial.mredrock.com.welcomefreshman.Bean.NatureCQUPTBean;
import freshmanspecial.mredrock.com.welcomefreshman.R;

/**
 * Created by Administrator on 2017/8/10 0010.
 */

public class MienRecyclerAdapter extends RecyclerView.Adapter<MienRecyclerAdapter.MyViewHolder>{
    //美在重邮  --->1    type
    private BeautyInCQUPTBean beautyBean;
    private Context context;
    private int type;
    //原创重邮  --->2    type
    private NatureCQUPTBean natureBean;
    public MienRecyclerAdapter(BeautyInCQUPTBean beautyBean, Context context, int type, NatureCQUPTBean natureBean){
        this.beautyBean = beautyBean;
        this.natureBean = natureBean;
        this.context = context;
        this.type = type;
    }
    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if(type ==1){
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.special_2017_mien_beauty_recycler_item,parent,false);
            MyViewHolder myViewHolder = new MyViewHolder(view);
            return myViewHolder;
        }
        else {
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.special_2017_mien_creat_recycler_item,parent,false);
            MyViewHolder myViewHolder = new MyViewHolder(view);
            return myViewHolder;
        }

    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        if (type == 1)
        {
            Glide.with(context).load(beautyBean.getData().get(position).getUrl()).into(holder.beauty_image);
            holder.beauty_text.setText(beautyBean.getData().get(position).getContent());
            holder.beauty_title.setText(beautyBean.getData().get(position).getTitle());
        }
        else {
            holder.crate_text.setText("《"+ natureBean.getData().get(position).getName()+"》");
            Glide.with(context).load(natureBean.getData().get(position).getCover()).into(holder.crate_img);
            holder.creat_btn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Uri uri =Uri.parse(natureBean.getData().get(position).getUrl());
                    Intent intent = new Intent(Intent.ACTION_VIEW,uri);
                    context.startActivity(intent);
                }
            });
        }

    }

    @Override
    public int getItemCount() {
        if (type==1)
        {
            return beautyBean.getData().size();

        }else {
            return natureBean.getData().size();

        }
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        ImageView beauty_image,crate_img;
        TextView beauty_text,beauty_title,crate_text;
        ImageButton creat_btn;
        public MyViewHolder(View itemView) {
            super(itemView);
            creat_btn = itemView.findViewById(R.id.creat_btn);
            beauty_image = itemView.findViewById(R.id.beauty_img_item);
            beauty_text = itemView.findViewById(R.id.beauty_text_item);
            beauty_title = itemView.findViewById(R.id.beauty_title_item);
            crate_img = itemView.findViewById(R.id.create_img);
            crate_text = itemView.findViewById(R.id.create_text);
        }
    }
}
